package cn.edu.ctbu.studentmanage.service.impl;

import cn.edu.ctbu.studentmanage.domain.Score;
import cn.edu.ctbu.studentmanage.repository.ScoreRepository;
import cn.edu.ctbu.studentmanage.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreImplService implements ScoreService {
    @Autowired
    private ScoreRepository scoreRepository;
    /**
     * 查询所有的成绩信息
     * @return
     */
    public List<Score> findAll(){

        return scoreRepository.findAll();
    }

    /**
     * 分页
     * @param pageable
     * @return
     */
    public Page<Score> findAll(Pageable pageable) {

        return scoreRepository.findAll(pageable);
    }
    /**
     * 分页加动态查询
     * @param scoreExample
     * @param pageable
     * @return
     */
    public Page<Score> findAll(Example<Score> scoreExample, Pageable pageable){
        return scoreRepository.findAll(scoreExample,pageable);
    }
    /**
     * 根据id获取某一成绩信息
     * @param id
     * @return
     */
    public Score getById(Integer id){

        return scoreRepository.findById(id).orElse(null);
    }
    /**
     * 更新成绩信息
     * @param score
     */
    public void update(Score score){
        scoreRepository.save(score);
    }
    /**
     * 根据id删除某一成绩信息
     * @param id
     */
    public void delete(Integer id){
        scoreRepository.deleteById(id);
    }
    /**
     * 插入新的成绩信息
     * @param score
     */
    public void Insert(Score score){ scoreRepository.save(score);
    }

}
